/*
 * @(#)AlphaGenerator.java    Aug 16, 2010
 *
 * Copyright 2009 Nyber Shanghai, Inc. All rights reserved.
 */

package com.lab.puzzle;

/**
 * 设计一个能随机产生100个大写英文字母的方法, 在该方法中统计产生了多少元音字母, 并输出这个数字.
 *
 * @author nickevin@gmail.com
 * @version Aug 16, 2010 8:31:19 PM
 */

public class AlphabetGenerator {

    private static final int SIZE = 100, SEED = 26, START = 97;
    private static final char[] AEIOU = { 'a', 'e', 'i', 'o', 'u' };

    public static int count() {
        return compare(generate(), AEIOU);
    }

    public static int compare(char[] alphabet, char[] aeiou) {
        int flag = 0;
        for (int i = 0; i < alphabet.length; i++) {
            for (int j = 0; j < aeiou.length; j++) {
                if (alphabet[i] == aeiou[j]) {
                    System.out.println(alphabet[i] + " " + aeiou[j]);
                    flag++;
                }
            }
        }

        return flag;
    }

    public static char[] generate() {
        char[] alphabet = new char[SIZE];
        for (int i = 0; i < SIZE; i++) {
            char alpha = (char) (Math.random() * SEED + START);
            alphabet[i] = alpha;
        }

        return alphabet;
    }
}
